//
// Button groups
// --------------------------------------------------

// Make the div behave like a button
.button-group,
.button-group-vertical {
  position: relative;
  display: inline-block;
  vertical-align: middle; // match .button alignment given font-size hack above
  > .button {
    position: relative;
    float: left;
    // Bring the "active" button to the front
    &:hover,
    &:focus,
    &:active,
    &.active {
      z-index: 2;
    }
    &:focus {
      // Remove focus outline when dropdown JS adds it after closing the menu
      outline: 0;
    }
  }
}

// Prevent double borders when buttons are next to each other
.button-group {
  .button + .button,
  .button + .button-group,
  .button-group + .button,
  .button-group + .button-group {
    margin-left: -1px;
  }
}

// Optional: Group multiple button groups together for a toolbar
.button-toolbar {
  margin-left: -5px; // Offset the first child's margin
  // &:extend(.clearfix all);
  .clearfix();

  .button-group,
  .input-group {
    float: left;
  }
  > .button,
  > .button-group,
  > .input-group {
    margin-left: 5px;
  }
}

.button-group > .button:not(:first-child):not(:last-child):not(.dropdown-toggle) {
  border-radius: 0;
}

// Set corners individual because sometimes a single button can be in a .button-group and we need :first-child and :last-child to both match
.button-group > .button:first-child {
  margin-left: 0;
  &:not(:last-child):not(.dropdown-toggle) {
    .border-right-radius(0);
  }
}
// Need .dropdown-toggle since :last-child doesn't apply given a .dropdown-menu immediately after it
.button-group > .button:last-child:not(:first-child),
.button-group > .dropdown-toggle:not(:first-child) {
  .border-left-radius(0);
}

// Custom edits for including button-groups within button-groups (useful for including dropdown buttons within a button-group)
.button-group > .button-group {
  float: left;
}
.button-group > .button-group:not(:first-child):not(:last-child) > .button {
  border-radius: 0;
}
.button-group > .button-group:first-child {
  > .button:last-child,
  > .dropdown-toggle {
    .border-right-radius(0);
  }
}
.button-group > .button-group:last-child > .button:first-child {
  .border-left-radius(0);
}

// On active and open, don't show outline
.button-group .dropdown-toggle:active,
.button-group.open .dropdown-toggle {
  outline: 0;
}


// Sizing
//
// Remix the default button sizing classes into new ones for easier manipulation.

.button-group-mini > .button { .button-mini; }
.button-group-small > .button { .button-small; }
.button-group-large > .button { .button-large; }


// Split button dropdowns
// ----------------------

// Give the line between buttons some depth
.button-group > .button + .dropdown-toggle {
  padding-left: 8px;
  padding-right: 8px;
}
.button-group > .button-lg + .dropdown-toggle {
  padding-left: 12px;
  padding-right: 12px;
}

// The clickable button for toggling the menu
// Remove the gradient and set the same inset shadow as the :active state
.button-group.open .dropdown-toggle {
  .box-shadow(inset 0 3px 5px rgba(0,0,0,.125));

  // Show no shadow for `.button-link` since it has no other button styles.
  &.button-link {
    .box-shadow(none);
  }
}


// // Reposition the caret
// .button .caret {
//   margin-left: 0;
// }
// // Carets in other button sizes
// .button-lg .caret {
//   border-width: @caret-width-large @caret-width-large 0;
//   border-bottom-width: 0;
// }
// // Upside down carets for .dropup
// .dropup .button-lg .caret {
//   border-width: 0 @caret-width-large @caret-width-large;
// }


// Vertical button groups
// ----------------------

.button-group-vertical {
  > .button,
  > .button-group,
  > .button-group > .button {
    display: block;
    float: none;
    width: 100%;
    max-width: 100%;
  }

  // Clear floats so dropdown menus can be properly placed
  > .button-group {
    //&:extend(.clearfix all);
    .clearfix();
    > .button {
      float: none;
    }
  }

  > .button + .button,
  > .button + .button-group,
  > .button-group + .button,
  > .button-group + .button-group {
    margin-top: -1px;
    margin-left: 0;
  }
}

.button-group-vertical > .button {
  &:not(:first-child):not(:last-child) {
    border-radius: 0;
  }
  &:first-child:not(:last-child) {
    border-top-right-radius: @radius;
    .border-bottom-radius(0);
  }
  &:last-child:not(:first-child) {
    border-bottom-left-radius: @radius;
    .border-top-radius(0);
  }
}
.button-group-vertical > .button-group:not(:first-child):not(:last-child) > .button {
  border-radius: 0;
}
.button-group-vertical > .button-group:first-child:not(:last-child) {
  > .button:last-child,
  > .dropdown-toggle {
    .border-bottom-radius(0);
  }
}
.button-group-vertical > .button-group:last-child:not(:first-child) > .button:first-child {
  .border-top-radius(0);
}



// Justified button groups
// ----------------------

.button-group-justified {
  display: table;
  width: 100%;
  table-layout: fixed;
  border-collapse: separate;
  > .button,
  > .button-group {
    float: none;
    display: table-cell;
    width: 1%;
  }
  > .button-group .button {
    width: 100%;
  }
}


// Checkbox and radio options
//
// In order to support the browser's form validation feedback, powered by the
// `required` attribute, we have to "hide" the inputs via `opacity`. We cannot
// use `display: none;` or `visibility: hidden;` as that also hides the popover.
// This way, we ensure a DOM element is visible to position the popover from.
//
// See https://github.com/twbs/bootstrap/pull/12794 for more.

[data-toggle="buttons"] > .button > input[type="radio"],
[data-toggle="buttons"] > .button > input[type="checkbox"] {
  position: absolute;
  z-index: -1;
  opacity: 0;
}
